import {Request, Response} from 'express'
import {Controller, Get, Post, Auth, generateToken} from '../uitl'
// import UserService from '../service/userService'

@Controller('/todo')
class ToDoController {
  @Get('/menuData')
  public login(
    req: Request,
    res: Response
  ): Response<any, Record<string, any>> {
    console.log(req.body)
    return res.send({
      success: true,
      data: [
        {
          name: 'list',
          label: '列表页',
          index: 'list',
          children: [
            {
              name: 'baseList',
              label: '基础列表页',
              index: 'baseList',
              children: [
                {
                  name: 'baseTable',
                  label: '基础表格页',
                  index: 'baseTable',
                  children: [],
                },
                {
                  name: 'baseTable01',
                  label: '基础表格页01',
                  index: 'baseTable01',
                  children: [],
                },
              ],
            },
            {
              name: 'baseList001',
              label: '基础列表页001',
              index: 'baseList001',
              children: [
                {
                  name: 'baseTable001',
                  label: '基础表格页001',
                  index: 'baseTable001',
                  children: [],
                },
                {
                  name: 'baseTable01001',
                  label: '基础表格页01001',
                  index: 'baseTable01001',
                  children: [],
                },
              ],
            },
          ],
        },
        {
          name: 'demo',
          label: 'demo',
          index: 'demo',
          children: [
            {
              name: 'demo1',
              label: 'demo1',
              index: 'demo1',
              children: [],
            },
            {
              name: 'demo2',
              label: 'demo2',
              index: 'demo2',
              children: [],
            },
          ],
        },
        {
          name: 'test',
          label: 'test',
          index: 'test',
          children: [],
        },
      ],
    })
  }

  @Get('/baseTable')
  public getBaseTableData(
    req: Request,
    res: Response
  ): Response<any, Record<string, any>> {
    console.log(req.query)
    const dataArrall = [
      {
        id: 1,
        date: '2016-05-03',
        name: 'Tom1',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 2,
        date: '2016-05-03',
        name: 'Tom2',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 3,
        date: '2016-05-03',
        name: 'Tom3',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 4,
        date: '2016-05-03',
        name: 'Tom4',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 5,
        date: '2016-05-03',
        name: 'Tom5',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 6,
        date: '2016-05-03',
        name: 'Tom6',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 7,
        date: '2016-05-03',
        name: 'Tom7',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 8,
        date: '2016-05-03',
        name: 'Tom8',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 9,
        date: '2016-05-03',
        name: 'Tom9',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 10,
        date: '2016-05-03',
        name: 'Tom10',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 11,
        date: '2016-05-03',
        name: 'Tom11',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 12,
        date: '2016-05-03',
        name: 'Tom12',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 13,
        date: '2016-05-03',
        name: 'Tom13',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 14,
        date: '2016-05-03',
        name: 'Tom14',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 15,
        date: '2016-05-03',
        name: 'Tom15',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 16,
        date: '2016-05-03',
        name: 'Tom16',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 17,
        date: '2016-05-03',
        name: 'Tom17',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 18,
        date: '2016-05-03',
        name: 'Tom18',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 19,
        date: '2016-05-03',
        name: 'Tom19',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 20,
        date: '2016-05-03',
        name: 'Tom20',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 21,
        date: '2016-05-03',
        name: 'Tom21',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 22,
        date: '2016-05-03',
        name: 'Tom22',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 23,
        date: '2016-05-03',
        name: 'Tom23',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 24,
        date: '2016-05-03',
        name: 'Tom24',
        address: 'No. 189, Grove St, Los Angeles',
      },
      {
        id: 25,
        date: '2016-05-03',
        name: 'Tom25',
        address: 'No. 189, Grove St, Los Angeles',
      },
    ]
    const dataArr1 = dataArrall.slice(0, 14)
    const dataArr2 = dataArrall.slice(14)
    let result
    console.log(req.query.curPage)
    const curPage = Number(req.query.curPage)
    const pageSize = Number(req.query.pageSize)
    const type = Number(req.query.type)
    if (type == 0) {
      result = {
        curPage: curPage,
        pageSize: pageSize,
        total: dataArrall.length,
        data: dataArrall.slice((curPage - 1) * pageSize, curPage * pageSize),
      }
    } else if (type == 1) {
      result = {
        curPage: curPage,
        pageSize: pageSize,
        total: dataArr1.length,
        data: dataArr1.slice((curPage - 1) * pageSize, curPage * pageSize),
      }
    } else if (type == 2) {
      result = {
        curPage: curPage,
        pageSize: pageSize,
        total: dataArr2.length,
        data: dataArr2.slice((curPage - 1) * pageSize, curPage * pageSize),
      }
    }
    return res.send({
      success: true,
      data: result,
    })
  }

  // 装饰器 就近执行 先Auth, 再Post
  @Post('/reset/:id')
  @Auth
  public reset(
    req: Request,
    res: Response
  ): Response<any, Record<string, any>> {
    return res.send({success: true, data: 'reset' + req.params.id})
  }
}

export default ToDoController
